<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>欢迎使用扫码呼叫服务</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status0.4875remstyle" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<meta content="maximum-dpr=1" name="flexible" />
<%@ include file="/include/wx_main_include.jsp"%>
<link rel="stylesheet" href="${path}/static/myjs/information/weixin/css/base.css?v=${css_version}">
<link rel="stylesheet" href="${path}/static/myjs/information/weixin/css/mui.css?v=${css_version}" />
<link rel="stylesheet" href="${path}/static/myjs/information/weixin/css/new_file.css?v=${css_version}" />
<link rel="stylesheet" href="${path}/static/myjs/information/weixin/css/iconfont.css?v=${css_version}">
<link rel="stylesheet" href="${path}/static/myjs/information/weixin/css/mui-order.css?v=${css_version}">
<link rel="stylesheet" href="${path}/static/myjs/information/weixin/css/iconfont.css?v=${css_version}">
</head>
<body>
	<div id="view" class="bg-gray">
		<div id="top-fixed">
			<header class="mui-bar mui-bar-nav">
				<a class="  mui-icon mui-icon-left-nav mui-pull-left"></a>
				<h1 class="mui-title">订单提交</h1>
			</header>
		</div>
		<div class="scroll-wrap">
			<div class="scroll-content">
				<div class="order-status">
					<div class="order-success">
						<c:if test="${pd.action=='success'}">
							<i class="iconfont icon-chenggong1"></i>
						</c:if>
						<c:if test="${pd.action=='fail'}">
							<i class="iconfont icon-unie046"></i>
						</c:if>
						<p class="mui-h4 fontcolor-p">${pd.action=='success'?'订单支付成功':'订单支付异常'}</p>
						<c:if test="${pd.action=='success'}">
							<p class="mui-h2 mt-ten fontcolor-red">
								<span></span>
							</p>
							<p class="mui-h3 fontcolor-p mt-ten"> </p>
						</c:if>
					</div>
					<%-- <div class="order-status-btns">
						<button type="button" class="order-evaluate-btn mui-btn-green" id="orderBtn">查看订单</button>
						<c:if test="${result.FLAG=='FAIL'}">
							<button class="order-evaluate-btn mui-btn-orange" id="pay">继续支付</button>
						</c:if>
					</div> --%>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" charset="utf-8">
    var payJson={};

	$(function() {
		$(".mui-icon-left-nav").on("click",function(){
			window.location.href = basePath+'m/home/index?CHANNEL=${result.CHANNEL}&OPENID=${result.OPENID}&BUSINESS_ID=${result.BUSINESS_ID}&RAMADHIN=${result.RAMADHIN}';
		});
		//=========浏览器后退处理=========
		function pushHistory() {
			var url = basePath + "m/home/index.ndo?CHANNEL=${result.CHANNEL}&BUSINESS_ID=${result.BUSINESS_ID}&OPENID=${result.OPENID}&RAMADHIN=${result.RAMADHIN}";
			window.addEventListener("popstate", function(e) {
				window.location.href = url;
			}, false);
			window.history.pushState(null, "title", "#");
		}
		var ver = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);  
		 if(ver!=null){
		 ver = parseInt(ver[1], 10); 
		if(ver<9)  {   
		}  else{
		pushHistory();
		}}
		//=========浏览器后退处理=========
		var me = this;
		var _global = {
			'BUSINESS_ID' :  '${result.BUSINESS_ID}',
			'OPENID' :  '${result.OPENID}',
			'CHANNEL' :  '${result.CHANNEL}',
			'RAMADHIN' :  '${result.RAMADHIN}',
			'prepay_id' : '${result.WXPREPAYID}',
			'orderid' : '${result.ORDER_ID}',
			'payJson':{}
		};
		$('#orderBtn').on('click', function() {
			location.href = '${path}/weixinHome/toOrderList?CHANNEL='+ _global.CHANNEL+'&BUSINESS_ID=' + _global.BUSINESS_ID+ '&OPENID=' + _global.OPENID+"&RAMADHIN="+ _global.RAMADHIN;
		});
		$('#pay').on('click', function() {
			if(_global.CHANNEL!="WX"){
				//支付宝支付
					var params = [ {
						name : 'ORDER_ID',
						value : _global.orderid
					}, {
						name : 'CHANNEL',
						value : _global.CHANNEL
					}, {
						name : 'OPENID',
						value : _global.OPENID 
					}, {
						name : 'TYPE',
						value : 'PAY_MODE_ALI_PAY'
					} ];
				eachInstall(rootpath + '/m/home/payApi', params, null, 'post');
			}else{
				mui.ajax(rootpath + '/m/home/getWXPayJson.ndo', {
					data : {
						ORDER_ID:'${result.ORDER_ID}',
						BUSINESS_ID:'${result.BUSINESS_ID}'
					},
					dataType : 'json',
					type : 'post',
					timeout : 10000,
					success : function(data) {
						if(typeof data.dataset.payJson=='undefined'){
							alert("此订单已经支付,不能重复支付!");
							return;
						}
						if (data.status = '0000') {
							me.payJson=JSON.parse(data.dataset.payJson);
							callpay();
						} 
					}
				});
			}
		});
		
		function jsApiCall()
		{
		    WeixinJSBridge.invoke(
		        'getBrandWCPayRequest',
		        payJson,
		         function (res)
		         {
		            WeixinJSBridge.log(res.err_msg);
		            console.log(res.err_msg);
		            var url="";
		            if(res.err_msg == "get_brand_wcpay_request:ok" ) {
		            	url=basePath+"weixinHome/payResult?orderId="+_global.orderid+"&action=success&prepay_id="+_global.prepay_id+"&OPENID="+_global.OPENID;
		            }else{
		            	url=basePath+"weixinHome/payResult?orderId="+_global.orderid+"&action=fail&prepay_id="+_global.prepay_id+"&OPENID="+_global.OPENID;
		            }     
		            window.location.href=url;
		          }
		     );
		}

		function callpay()
		{
		    if (typeof WeixinJSBridge == "undefined")
		    {
		        if (document.addEventListener)
		        {
		            document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
		        }
		        else if (document.attachEvent)
		        {
		            document.attachEvent('WeixinJSBridgeReady', jsApiCall);
		            document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
		        }
		    }
		    else
		    {
		        jsApiCall();
		    }
		}
	});
</script>
</html>